#include "audio.h"

namespace SkyID
{

//- Audio --------------------------------------------------------------------

namespace Audio
{

bool initialize(const Config &config)
{
#ifndef SKYID_DISABLE_SOUND
	ALCdevice *alcDevice = alcOpenDevice(NULL);
	if (!alcDevice)
	{
		LOG_MSG("Audio: open default audio device failed (%d)", alcGetError(NULL));
		return false;
	}

	ALCcontext *alcContext = alcCreateContext(alcDevice, NULL);
	if (!alcContext)
	{
		LOG_MSG("Audio: create audio context failed (%d)", alcGetError(alcDevice));
		return false;
	}

	alcMakeContextCurrent(alcContext);

	LOG_MSG("Audio: initialized");
	return true;
#else
	return true;
#endif
}

void shutdown()
{
#ifndef SKYID_DISABLE_SOUND
	ALCcontext *alcContext = alcGetCurrentContext();
	ALCdevice *alcDevice = alcGetContextsDevice(alcContext);

	alcMakeContextCurrent(NULL);
	alcDestroyContext(alcContext);
	alcCloseDevice(alcDevice);
	LOG_MSG("Audio: shutdown");
#endif
}

} // namespace Audio

} // namespace SkyID
